<!-- 推荐人管理员管理端统计页面 -->
<template>
  <div class="">
    <div class="search-chart">
      <el-form ref="search" :model="search" :inline="true" :rules="rules">

        <el-form-item prop="date">
          <!-- <el-date-picker v-model="search.date" type="date" placeholder="请选择日期" style="width:140px" /> -->
          <el-date-picker
            v-model="search.date"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          />
        </el-form-item>

        <el-form-item>
          <el-button type="primary" style="margin-left:10px" @click="submit('search')">提交</el-button>
          <el-button icon="el-icon-refresh" circle @click="refresh()" />
        </el-form-item>
      </el-form>
    </div>
    <div>
      <div id="cardArea">
        <el-card id="totalCount" class="box-card">
          <div class="info-label"><b>订单数量</b></div>
          <div class="info-label2">
            <svg-icon icon-class="table" class="icon" class-name="card-panel-icon" style="color:#409EFF;font-size:50px;float:left" />
            <span id="totalUser-num" class="num">{{ totalOrders }}<span style="font-size:15px">笔</span></span>
          </div>
        </el-card>

        <el-card id="contactCount" class="box-card">
          <div class="info-label"><b>订单金额</b></div>
          <div class="info-label2" style="color:#67C23A  ">
            <svg-icon icon-class="form" class="icon" class-name="card-panel-icon" style="font-size:50px;float:left" />
            <span id="contactUser-num" class="num">￥{{ totalMoney }}<span style="font-size:15px">元</span></span>
          </div>
        </el-card>
      </div>
      <div id="cardArea">
        <el-card id="feverCount" class="box-card">
          <div class="info-label"><b>分期订单数量</b></div>
          <div class="info-label2" style="color:#F56C6C">
            <svg-icon icon-class="table" class="icon" class-name="card-panel-icon" style="font-size:50px;float:left" />
            <span id="feverUser-num" class="num">{{ stageOrders }}<span style="font-size:15px">笔</span>  </span>
          </div>
        </el-card>

        <el-card id="hospitalCount" class="box-card">
          <div class="info-label"><b>分期订单金额</b></div>
          <div class="info-label2" style="color: #E6A23C">
            <svg-icon icon-class="form" class="icon" class-name="card-panel-icon" style="font-size:50px;float:left" />
            <span id="hostipalUser-num" class="num">￥{{ stageMoney }}<span style="font-size:15px">元</span></span>
          </div>
        </el-card>
      </div>
    </div>
    <div id="table-area">
      <el-table
        v-loading="listLoading"
        :data="list.slice((currentPage-1)*pagesize,currentPage*pagesize)"
        element-loading-text="Loading"
        border
        fit
        highlight-current-row
      >

        <el-table-column
          label="序号"
          type="index"
          width="80"
          align="center"
        >
          <template scope="scope">
            <span>{{ (currentPage - 1) * pagesize + scope.$index + 1 }}</span>
          </template>
        </el-table-column>

        <el-table-column
          align="center"
          prop="RealName"
          label="代理人"
        />

        <el-table-column
          align="center"
          prop="OrgName"
          label="品牌名称"
        />

        <el-table-column
          align="center"
          prop="CampusName"
          label="机构名称"
        />

        <el-table-column
          align="center"
          prop="ALLcount"
          label="订单数量"
        />

        <el-table-column
          align="center"
          prop="ALLmoney"
          label="订单金额"
        />

        <el-table-column
          align="center"
          prop="fenqicount"
          label="分期订单数量"
        />

        <el-table-column
          align="center"
          prop="fenqiprice"
          label="分期订单金额"
        />

        <el-table-column
          align="center"
          prop="wxcount"
          label="微信订单数量"
        />

        <el-table-column
          align="center"
          prop="wxprice"
          label="微信订单金额"
        />

        <el-table-column
          align="center"
          prop="kuaiJiecount"
          label="快捷订单数量"
        />

        <el-table-column
          align="center"
          prop="kuaiJieprice"
          label="快捷订单金额"
        />

      </el-table>

      <div id="pages">
        <el-pagination
          :current-page="currentPage"
          :page-sizes="[5,10]"
          :page-size="pagesize"
          layout="total, sizes,prev, pager, next"
          :total="list.length"
          prev-text="上一页"
          next-text="下一页"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
  </div>
</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// 例如：import 《组件名称》 from '《组件路径》';
import { countReBusiness, countReBusiness2 } from '@/api/statistic'
export default {
  name: 'RecommendStatistic',
  // import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    // 这里存放数据
    return {
      currentPage: 1, // 默认显示页面为1
      pagesize: 5, //    每页的数据条数
      list: [],
      listLoading: false,
      totalOrders: 0,
      totalMoney: 0,
      stageOrders: 0,
      stageMoney: 0,
      date1: '',
      date2: '',
      search: {
        date: ''
      },
      rules: {
        date: [
          { required: true, message: '请选择日期', trigger: 'blur' }
        ]
      }
    }
  },
  // 监听属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {},
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {
  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, // 生命周期 - 创建之前
  beforeMount() {}, // 生命周期 - 挂载之前
  beforeUpdate() {}, // 生命周期 - 更新之前
  updated() {}, // 生命周期 - 更新之后
  beforeDestroy() {}, // 生命周期 - 销毁之前
  destroyed() {}, // 生命周期 - 销毁完成
  activated() {},
  // 方法集合
  methods: {
    // 每页下拉显示数据
    handleSizeChange: function(size) {
      this.pagesize = size
    },
    // 点击第几页
    handleCurrentChange: function(currentPage) {
      this.currentPage = currentPage
    },
    handleClick(row) {
      console.log(row)
    },
    submit(formName) {
      this.listLoading = true
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.date1 = this.search.date[0]
          this.date2 = this.search.date[1]
          console.log(this.date1)
          console.log(this.date2)
          countReBusiness(this.date1, this.date2).then((resp) => {
            this.totalOrders = resp.obj.ALLcount
            this.totalMoney = resp.obj.ALLmoney / 100
            this.stageOrders = resp.obj.fenqicount
            this.stageMoney = resp.obj.fenqiprice / 100
            countReBusiness2(this.date1, this.date2).then((res) => {
              this.list = res.obj
              this.listLoading = false
            })
          })
          return true
        } else {
          this.$notify({
            title: '请正确填写',
            type: 'error'
          })
          return false
        }
      })
    },
    refresh() {
      this.search.date = []
      this.totalOrders = 0
      this.totalMoney = 0
      this.stageOrders = 0
      this.stageMoney = 0
      this.list = []
    }
  } // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>
<style  scoped>

#cardArea{
    margin: 50px;
    display: flex;
    justify-content: center;

}

 .box-card {
    margin-left: 30px;
    width: 400px;
    height: 180px;
  }

 .info-label{
    line-height: 50px;
    margin-top: 0px;
  }

  .info-label2{
    line-height: 100px;
    margin-top: 0px;
  }

  #totalUser-num{
  color: #409EFF;
  /* font-size: 35px; */
}

.info-label
{
  color: #606266;
  /* text-align: right; */
  /* font-size:35px; */
}

.num{
  float:right;
  text-align: right;
  font-size: 35px;
  margin-right: 10px;
  /* margin-left: 60%; */
}

.icon{
  margin-top: 15px;
  text-align: left;
}
.tab{
  margin: 0 auto;
  width: 1400px;
}
.pie{
   margin: 50px auto;
   width: 1400px;
}
#myPie1{
  width: 1300px;
  height: 540px;
}
#table-area{
  margin-left: 10px;
  margin-right: 10px;
}
#search-card {
  margin-left: 50px;
  margin-top: 30px;
  width: 100%;
  height: 70px;
  overflow-x: hidden;
}
.orders-card{
  width: 1400px;
  margin: 50px auto;
}
.search-chart{
 margin-top: 50px;
 display: flex;
 justify-content: center;
}
.orders-title{
  color: #606266;
  font-size: 24px;
  margin-bottom: 20px;
}
.download{
  float: right;
  margin-bottom: 15px;
  margin-right: 40px;
}
</style>
